﻿// <copyright file="BarracksOfBalgass.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

namespace MUnique.OpenMU.Persistence.Initialization.Maps
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using MUnique.OpenMU.AttributeSystem;
    using MUnique.OpenMU.DataModel.Configuration;
    using MUnique.OpenMU.GameLogic.Attributes;

    /// <summary>
    /// The initialization for the Barracks of Balgass map.
    /// </summary>
    internal class BarracksOfBalgass : BaseMapInitializer
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BarracksOfBalgass"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="gameConfiguration">The game configuration.</param>
        public BarracksOfBalgass(IContext context, GameConfiguration gameConfiguration)
            : base(context, gameConfiguration)
        {
        }

        /// <inheritdoc/>
        protected override byte MapNumber => 41;

        /// <inheritdoc/>
        protected override string MapName => "Barracks of Balgass";

        /// <inheritdoc />
        protected override void InitializeDropItemGroups()
        {
            base.InitializeDropItemGroups();

            var flameOfCondor = this.Context.CreateNew<DropItemGroup>();
            flameOfCondor.Chance = 0.001;
            flameOfCondor.Description = "Flame of Condor";
            flameOfCondor.PossibleItems.Add(this.GameConfiguration.Items.First(item => item.Group == 13 && item.Number == 52));
            this.MapDefinition!.DropItemGroups.Add(flameOfCondor);
            this.GameConfiguration.DropItemGroups.Add(flameOfCondor);
        }

        /// <inheritdoc/>
        protected override IEnumerable<MonsterSpawnArea> CreateSpawns()
        {
            var npcDictionary = this.GameConfiguration.Monsters.ToDictionary(npc => npc.Number, npc => npc);

            // NPCs:
            yield return this.CreateMonsterSpawn(npcDictionary[408], 119, 168, Direction.South); // Gatekeeper

            // Monsters:
            yield return this.CreateMonsterSpawn(npcDictionary[409], 039, 101); // Balram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[409], 044, 110); // Balram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[409], 052, 134); // Balram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[409], 067, 112); // Balram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[409], 087, 090); // Balram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[409], 090, 067); // Balram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[409], 090, 078); // Balram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[409], 071, 101); // Balram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[409], 064, 132); // Balram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[409], 109, 101); // Balram (Trainee Soldier)

            yield return this.CreateMonsterSpawn(npcDictionary[410], 098, 096); // Death Spirit (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[410], 122, 090); // Death Spirit (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[410], 125, 099); // Death Spirit (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[410], 137, 140); // Death Spirit (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[410], 140, 150); // Death Spirit (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[410], 044, 127); // Death Spirit (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[410], 057, 123); // Death Spirit (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[410], 079, 086); // Death Spirit (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[410], 101, 069); // Death Spirit (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[410], 121, 118); // Death Spirit (Trainee Soldier)

            yield return this.CreateMonsterSpawn(npcDictionary[411], 127, 127); // Soram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[411], 126, 166, 164, 164); // Soram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[411], 123, 160); // Soram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[411], 132, 156); // Soram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[411], 132, 136); // Soram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[411], 116, 103); // Soram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[411], 129, 146); // Soram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[411], 117, 098); // Soram (Trainee Soldier)
            yield return this.CreateMonsterSpawn(npcDictionary[411], 113, 109); // Soram (Trainee Soldier)
        }

        /// <inheritdoc/>
        protected override void CreateMonsters()
        {
            {
                var monster = this.Context.CreateNew<MonsterDefinition>();
                this.GameConfiguration.Monsters.Add(monster);
                monster.Number = 409;
                monster.Designation = "Balram (Trainee Soldier)";
                monster.MoveRange = 6;
                monster.AttackRange = 4;
                monster.ViewRange = 7;
                monster.MoveDelay = new TimeSpan(500 * TimeSpan.TicksPerMillisecond);
                monster.AttackDelay = new TimeSpan(1700 * TimeSpan.TicksPerMillisecond);
                monster.RespawnDelay = new TimeSpan(10 * TimeSpan.TicksPerSecond);
                monster.Attribute = 2;
                monster.NumberOfMaximumItemDrops = 1;
                var attributes = new Dictionary<AttributeDefinition, float>
                {
                    { Stats.Level, 117 },
                    { Stats.MaximumHealth, 75000 },
                    { Stats.MinimumPhysBaseDmg, 550 },
                    { Stats.MaximumPhysBaseDmg, 650 },
                    { Stats.DefenseBase, 480 },
                    { Stats.AttackRatePvm, 1200 },
                    { Stats.DefenseRatePvm, 370 },
                    { Stats.PoisonResistance, 23 },
                    { Stats.IceResistance, 23 },
                    { Stats.LightningResistance, 23 },
                    { Stats.FireResistance, 23 },
                };

                monster.AddAttributes(attributes, this.Context, this.GameConfiguration);
            }

            {
                var monster = this.Context.CreateNew<MonsterDefinition>();
                this.GameConfiguration.Monsters.Add(monster);
                monster.Number = 410;
                monster.Designation = "Death Spirit (Trainee Soldier)";
                monster.MoveRange = 6;
                monster.AttackRange = 4;
                monster.ViewRange = 7;
                monster.MoveDelay = new TimeSpan(500 * TimeSpan.TicksPerMillisecond);
                monster.AttackDelay = new TimeSpan(1700 * TimeSpan.TicksPerMillisecond);
                monster.RespawnDelay = new TimeSpan(10 * TimeSpan.TicksPerSecond);
                monster.Attribute = 2;
                monster.NumberOfMaximumItemDrops = 1;
                var attributes = new Dictionary<AttributeDefinition, float>
                {
                    { Stats.Level, 119 },
                    { Stats.MaximumHealth, 85000 },
                    { Stats.MinimumPhysBaseDmg, 580 },
                    { Stats.MaximumPhysBaseDmg, 680 },
                    { Stats.DefenseBase, 490 },
                    { Stats.AttackRatePvm, 1200 },
                    { Stats.DefenseRatePvm, 390 },
                    { Stats.PoisonResistance, 25 },
                    { Stats.IceResistance, 25 },
                    { Stats.LightningResistance, 25 },
                    { Stats.FireResistance, 25 },
                };

                monster.AddAttributes(attributes, this.Context, this.GameConfiguration);
            }

            {
                var monster = this.Context.CreateNew<MonsterDefinition>();
                this.GameConfiguration.Monsters.Add(monster);
                monster.Number = 411;
                monster.Designation = "Soram (Trainee Soldier)";
                monster.MoveRange = 6;
                monster.AttackRange = 2;
                monster.ViewRange = 7;
                monster.MoveDelay = new TimeSpan(500 * TimeSpan.TicksPerMillisecond);
                monster.AttackDelay = new TimeSpan(1700 * TimeSpan.TicksPerMillisecond);
                monster.RespawnDelay = new TimeSpan(10 * TimeSpan.TicksPerSecond);
                monster.Attribute = 2;
                monster.NumberOfMaximumItemDrops = 1;
                var attributes = new Dictionary<AttributeDefinition, float>
                {
                    { Stats.Level, 119 },
                    { Stats.MaximumHealth, 90000 },
                    { Stats.MinimumPhysBaseDmg, 600 },
                    { Stats.MaximumPhysBaseDmg, 700 },
                    { Stats.DefenseBase, 500 },
                    { Stats.AttackRatePvm, 1200 },
                    { Stats.DefenseRatePvm, 390 },
                    { Stats.PoisonResistance, 25 },
                    { Stats.IceResistance, 25 },
                    { Stats.LightningResistance, 25 },
                    { Stats.FireResistance, 25 },
                };

                monster.AddAttributes(attributes, this.Context, this.GameConfiguration);
            }
        }
    }
}
